package chart;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ChartMgt extends HttpServlet {
	  public void init(ServletConfig config) throws ServletException {

	  }
	  protected void doGet(HttpServletRequest request, HttpServletResponse response)
	  throws ServletException, IOException {
	  request.setCharacterEncoding("UTF-8");
	  String sort = request.getParameter("sort");
	  response.setContentType("text/xml; charset=UTF-8");
	  response.setHeader("Cache-Control", "no-cache");

	  PrintWriter out = response.getWriter();

	  out.println("<response>");  	 

	  try {
	  Class.forName("oracle.jdbc.driver.OracleDriver");
	  Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","s4197417","melati0831");   
	  String sql = "select PollID, QuestionID from Poll_Question"; 
      PreparedStatement pstmt = conn.prepareStatement(sql); 
	  ResultSet rs = pstmt.executeQuery(sql);

	  while (rs.next()) {
	  out.println("<name>" + rs.getString("name") + "</name>");
	  }
	  } catch (SQLException e) {
	  e.printStackTrace();
	  } catch (ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	  out.println("</response>");
	  out.close();
	  }
	}
